var pageii = null;
var grid = null;
$(function() {
	
	grid = lyGrid({
		pagId : 'paging',
		l_column : [ {
			colkey : "patient_number",
			name : "编号",
		}, {
			colkey : "patient_name",
			name : "姓名",
			isSort:true,
		}, {
			colkey : "patient_sex",
			width:'80',
			name : "性别",
			isSort:true,
		}, {
			colkey : "patient_age",
			width:'80',
			name : "年龄"
		}, {
			colkey : "patient_phone",
			name : "手机号码",
		}, {
			colkey : "patient_address",
			name : "患者地址",
		}, {
			colkey : "create_time",
			name : "创建时间",
			isSort:true,
			renderData : function(rowindex, data, rowdata, column) {
				if (data == null || data == undefined || data == '') { 
					return "无";
				} else {
					return new Date(data).format("yyyy-MM-dd hh:mm:ss");
				}
			}
		}, {
			colkey : "update_time",
			name : "修改时间",
			isSort:true,
			renderData : function(rowindex,data, rowdata, column) {
				if (data == null || data == undefined || data == '') { 
					return "无";
				} else {
					return new Date(data).format("yyyy-MM-dd hh:mm:ss");
				}
			}
		}, {
			colkey : "id",
			name : "操作",
			isSort:false,
			renderData : function(rowindex,data, rowdata, column) {
				if (data == null || data == undefined || data == '') { 
					return "无";
				} else {
					return "<a href='javascript:querycase("+data+")'>查看病历</a>";
				}
			}
		}],
		data : {'patientFormMap.type':'day'},
		jsonUrl : rootPath + '/patient/findByPage.shtml',
		checkbox : false,
		serNumber : true
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
});

function querycase(patient_id){
	url = rootPath + '/case/findBypatient.shtml?patient_id='+patient_id;
	pageii = layer.open({
		title : "病历",
		type : 2,
		skin: 'layui-layer-rim',
		area : [ "900px", "80%" ],
		content : url      
	});
}

function query(type){
	if(type=="condition"){
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	}else{
		grid.setOptions({
			data : {'patientFormMap.type':type}
		});
	}
}